/*
 * Copyright (C) 2008 Rob Cash
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SubscriptionTypeChooser.java
 *
 * Created on Dec 14, 2008, 12:33:34 PM
 */

package org.robcash.apps.messagepopup.view.components;

import javax.swing.ButtonModel;
import org.robcash.commons.swing.wizard.WizardComponent;

/**
 *
 * @author Rob
 */
public class SubscriptionTypeChooser extends WizardComponent {

    public static final String NONE = "none";

    public static final String LOCAL_FILE = "localFile";

    public static final String REMOTE_FILE = "remoteFile";

    public static final String REMOTE_SERVICE = "remoteService";

    /** Creates new form SubscriptionTypeChooser */
    public SubscriptionTypeChooser() {
        initComponents();
    }

    /**
     * Get the selected subscription type
     * @return type of subscription
     */
    public String getSelectedSubscriptionType() {
        ButtonModel selectedModel = subscriptionTypeButtonGroup.getSelection();
        if ( selectedModel == null ) {
            return NONE;
        }
        else if ( localFileRadioButton.isSelected() ) {
            return LOCAL_FILE;
        }
        else if ( remoteFileRadioButton.isSelected() ) {
            return REMOTE_FILE;
        }
        else {
            return REMOTE_SERVICE;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        subscriptionTypeButtonGroup = new javax.swing.ButtonGroup();
        instructions = new javax.swing.JLabel();
        localFileRadioButton = new javax.swing.JRadioButton();
        localFileHelp = new javax.swing.JLabel();
        remoteFileRadioButton = new javax.swing.JRadioButton();
        remoteFileHelp = new javax.swing.JLabel();
        remoteServiceRadioButton = new javax.swing.JRadioButton();
        remoteServiceHelp = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(org.robcash.apps.messagepopup.Main.class).getContext().getResourceMap(SubscriptionTypeChooser.class);
        instructions.setText(resourceMap.getString("instructions.text")); // NOI18N
        instructions.setName("instructions"); // NOI18N

        subscriptionTypeButtonGroup.add(localFileRadioButton);
        localFileRadioButton.setText(resourceMap.getString("localFileRadioButton.text")); // NOI18N
        localFileRadioButton.setName("localFileRadioButton"); // NOI18N
        localFileRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonActionPerformed(evt);
            }
        });

        localFileHelp.setLabelFor(localFileRadioButton);
        localFileHelp.setText(resourceMap.getString("localFileHelp.text")); // NOI18N
        localFileHelp.setName("localFileHelp"); // NOI18N

        subscriptionTypeButtonGroup.add(remoteFileRadioButton);
        remoteFileRadioButton.setText(resourceMap.getString("remoteFileRadioButton.text")); // NOI18N
        remoteFileRadioButton.setName("remoteFileRadioButton"); // NOI18N
        remoteFileRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonActionPerformed(evt);
            }
        });

        remoteFileHelp.setLabelFor(remoteFileRadioButton);
        remoteFileHelp.setText(resourceMap.getString("remoteFileHelp.text")); // NOI18N
        remoteFileHelp.setName("remoteFileHelp"); // NOI18N

        subscriptionTypeButtonGroup.add(remoteServiceRadioButton);
        remoteServiceRadioButton.setText(resourceMap.getString("remoteServiceRadioButton.text")); // NOI18N
        remoteServiceRadioButton.setEnabled(false);
        remoteServiceRadioButton.setName("remoteServiceRadioButton"); // NOI18N
        remoteServiceRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonActionPerformed(evt);
            }
        });

        remoteServiceHelp.setLabelFor(remoteServiceRadioButton);
        remoteServiceHelp.setText(resourceMap.getString("remoteServiceHelp.text")); // NOI18N
        remoteServiceHelp.setEnabled(false);
        remoteServiceHelp.setName("remoteServiceHelp"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(remoteServiceHelp))
                    .addComponent(remoteServiceRadioButton)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(remoteFileHelp))
                    .addComponent(remoteFileRadioButton)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(localFileHelp))
                    .addComponent(localFileRadioButton)
                    .addComponent(instructions))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(instructions)
                .addGap(18, 18, 18)
                .addComponent(localFileRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(localFileHelp)
                .addGap(18, 18, 18)
                .addComponent(remoteFileRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(remoteFileHelp)
                .addGap(18, 18, 18)
                .addComponent(remoteServiceRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(remoteServiceHelp)
                .addContainerGap(104, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void radioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioButtonActionPerformed
        if ( evt.getSource().equals(localFileRadioButton) ) {
            System.out.println("Local file action");
            fireChangeListenerStateChanged();
        }
        else if ( evt.getSource().equals(remoteFileRadioButton) ) {
            System.out.println("Remote file action");
            fireChangeListenerStateChanged();
        }
        else if ( evt.getSource().equals(remoteServiceRadioButton) ) {
            System.out.println("Remote service action");
            fireChangeListenerStateChanged();
        }
    }//GEN-LAST:event_radioButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel instructions;
    private javax.swing.JLabel localFileHelp;
    private javax.swing.JRadioButton localFileRadioButton;
    private javax.swing.JLabel remoteFileHelp;
    private javax.swing.JRadioButton remoteFileRadioButton;
    private javax.swing.JLabel remoteServiceHelp;
    private javax.swing.JRadioButton remoteServiceRadioButton;
    private javax.swing.ButtonGroup subscriptionTypeButtonGroup;
    // End of variables declaration//GEN-END:variables

}
